package generic;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-10-24
 * Time:21:04
 */
//代表当前的类是一个泛型类
    //T是一个占位符
    //自动进行类型的检查
    //自动进行类型的转换
    //泛型的编译，就是一种擦除机制 ： 擦除为object;
class Mystack <T>{
    public T[] elem;
    public int usedSize;

    public Mystack(){
        this.elem = (T[]) new Object[5];
    }
    public void push(T val){
        this.elem[this.usedSize++] = val;
    }

    public T getTop() {
        return this.elem[this.usedSize - 1];
    }
}
public class TestDemo {
    public static void main(String[] args) {

    }
    public static void main1(String[] args) {
        Mystack<Integer> mystack = new Mystack<>();
        System.out.println(mystack);//打印的东西没有尖括号
        mystack.push(1);
        int val = mystack.getTop();
        System.out.println(val);
    }
}
